import 'dart:core';
import 'dart:io';

import 'package:flutter_syt/api/EncryptUtils.dart';
import 'package:flutter_syt/application.dart';
import 'package:flutter_syt/datas/access_token.dart';
import 'package:flutter_syt/datas/article_item.dart';
import 'package:flutter_syt/datas/auth_type.dart';
import 'package:flutter_syt/datas/banner_item.dart';
import 'package:flutter_syt/datas/can_comment_model.dart';
import 'package:flutter_syt/datas/cards_item.dart';
import 'package:flutter_syt/datas/category_v3_model.dart';
import 'package:flutter_syt/datas/categroy_item.dart';
import 'package:flutter_syt/datas/epidemic_item.dart';
import 'package:flutter_syt/datas/feedback_item.dart';
import 'package:flutter_syt/datas/game_detail_item.dart';
import 'package:flutter_syt/datas/game_item.dart';
import 'package:flutter_syt/datas/game_medal_rank_model.dart';
import 'package:flutter_syt/datas/game_subcription_item.dart';
import 'package:flutter_syt/datas/game_tab.dart';
import 'package:flutter_syt/datas/game_video_list_item.dart';
import 'package:flutter_syt/datas/health_about_info.dart';
import 'package:flutter_syt/datas/home_announcement_mdoel.dart';
import 'package:flutter_syt/datas/image_response.dart';
import 'package:flutter_syt/datas/index_setting.dart';
import 'package:flutter_syt/datas/message_list_model.dart';
import 'package:flutter_syt/datas/roles_item.dart';
import 'package:flutter_syt/datas/station_item.dart';
import 'package:flutter_syt/datas/upload_data_model.dart';
import 'package:flutter_syt/datas/user_comment_model.dart';
import 'package:flutter_syt/datas/user_info.dart';
import 'package:flutter_syt/datas/venue_item.dart';
import 'package:flutter_syt/datas/volunteer_list.dart';
import 'package:flutter_syt/datas/weather_item.dart';
import 'package:flutter_syt/domain/games/game_single_live_detail.dart';
import 'package:flutter_syt/domain/games/venue_subcription_item.dart';
import 'package:flutter_syt/domain/games/wardList.dart';
import 'package:flutter_syt/domain/home/home_cell.dart';
import 'package:flutter_syt/domain/login/login_area_code_dialog.dart';
import 'package:flutter_syt/domain/mine/signin_page.dart';
import 'package:flutter_syt/domain/widgets/stupid_tabs.dart';
import 'package:flutter_syt/generated/l10n.dart';
import 'package:flutter_syt/root_widget.dart';
import 'package:flutter_syt/starter/http/http_manager.dart';
import 'package:flutter_syt/utils/utils_dlog.dart';

import '../global_easy_loading.dart';

/// API 命名空间
class API {
  static var shared = API._();

  API._();

  APICommon common = APICommon();
  APILogin login = APILogin();
  APIUser user = APIUser();
  APIArticle article = APIArticle();
  APINotificationBind notificationBind = APINotificationBind();
  Epidemic epidemic = Epidemic();
  APIVolunteer volunteer = APIVolunteer();
  APIVenue venue = APIVenue();
  APIGame game = APIGame();
  Station station = Station();
  JSBridge bridge = JSBridge();
  FeedBack feedback = FeedBack();
}

///公共分类
class APICommon {
  ///获取天气
  ///
  ///http://yapi.scrm.buerkongjian.com/project/326/interface/api/23215
  Future<WeatherItem> weather() async {
    var json = await HttpManager.shared.get("/index/weather");
    return WeatherItem(json);
  }

  ///获取配置
  ///
  Future getSysTemBatch({List? keys}) async {
    try {
      var json =
          await HttpManager.shared.post("/system-setting/batch-get", params: {
        'keys': keys ??
            [
              "customer_hotline",
              "reserve_hotline",
              "hotline_copywriting",
              "email_copywriting",
              "email_feedback",
              "reserve_copywriting",
              "online_copywriting",
            ]
      });
      // HttpManager.shared.get("/protocol/get", params: {'type': 6});

      return json;
    } catch (e) {
      return {};
    }
  }

  ///首页banner
  ///
  ///http://yapi.scrm.buerkongjian.com/project/326/interface/api/23219
  Future<List<BannerItem>> banner() async {
    var json = await HttpManager.shared.get("/index/banner") as List<dynamic>;
    return json.map((e) => BannerItem(e)).toList();
  }

  ///栏目列表
  ///
  ///http://yapi.scrm.buerkongjian.com/project/326/interface/api/23223
  ///
  /// [isHome] 1:首页，0：其它
  Future<List<CategoryItem>> category(int isHome) async {
    var json = await HttpManager.shared
        .get("/index/user-category?limit=$isHome") as List<dynamic>;
    return json.map((e) => CategoryItem((e))).toList();
  }

  Future<List<CategoryItem>> allCategory() async {
    var json =
        await HttpManager.shared.get("/index/category-v2") as List<dynamic>;
    return json.map((e) => CategoryItem((e))).toList();
  }

  ///首页栏目-v3
  ///
  ///http://yapi.scrm.buerkongjian.com/mock/326/index/category-v3
  Future<CategoryV3Model> getCategoryHome() async {
    var json = await HttpManager.shared.get("/index/category-v3");
    return CategoryV3Model.fromJson(json);
  }

  ///系统配置
  ///feedback_setting
  ///http://yapi.scrm.buerkongjian.com/project/326/interface/api/28520
  Future<dynamic> getSystemSetting(String key) async {
    var json = await HttpManager.shared.get("/system-setting/get?key=$key");
    return json;
  }

  Future<List<HomeAnnouncementMdoel>> getHomeAnnouncement({
    String? id,
  }) async {
    // ${search != null ?

    var json = await HttpManager.shared
            .get("/index/announcement${id != null ? '?classify_id=$id' : ''}")
        as List;
    return json
        .map((e) => HomeAnnouncementMdoel.fromJson(e as Map<String, dynamic>))
        .toList();
    // return json;
  }

  ///公告分类
  ///http://yapi.msvoicepower.com/project/326/interface/api/546
  ///
  Future<List<ScrollerTabEntity>> getAnnouncementTabs() async {
    var json =
        await HttpManager.shared.get("/index/announcement-classify") as List;
    return json
        .map((e) =>
            ScrollerTabEntity.create('', e['name'], 0, '', id: "${e['id']}"))
        .toList();
  }

  ///栏目浏览统计
  ///
  ///http://yapi.scrm.buerkongjian.com/project/326/interface/api/29144
  Future<dynamic> getColumnStatistics(
    String name,
  ) async {
    // var lang = Intl.getCurrentLocale();
    // appContext.iOSInfo.identifierForVendor;
    String device = (Platform.isIOS
            ? appContext.iOSInfo.identifierForVendor
            : "${appContext.andriodInfo.model}_${appContext.andriodInfo.version.release}") ??
        '';
    device = device.replaceAll(" ", '_');
    var json = await HttpManager.shared.put("/index/column-statistics",
        params: {"column_name": name, "device": device});
    return json;
  }

  ///index/save-user-category
  Future<bool> saveCategory(List<String> ids) async {
    await HttpManager.shared
        .post("/index/save-user-category", params: {"data": ids});
    return true;
  }

  ///获取开屏
  ///
  ///http://yapi.scrm.buerkongjian.com/project/326/interface/api/23227
  Future<String> flash() async {
    var json = await HttpManager.shared.get("/index/flash");
    return json["image"] as String? ?? "";
  }

  ///设备启动
  ///
  ///http://yapi.scrm.buerkongjian.com/project/326/interface/api/30608
  Future startUpStatistics(String device) async {
    await HttpManager.shared
        .put("/index/start-up-statistics", params: {'device': device});
    return;
  }

  ///上传图片
  ///
  /// http://yapi.scrm.buerkongjian.com/project/326/interface/api/23388
  Future<ImageResponse> uploadImage(String filePath) async {
    var json = await HttpManager.shared.upload("/upload/image", filePath);
    return ImageResponse(json);
  }

  ///上传文件
  ///
  /// http://yapi.scrm.buerkongjian.com/project/326/interface/api/24636
  Future<ImageResponse> uploadFile(String name, String fileUrl) async {
    var json = await HttpManager.shared
        .upload("/upload/file", fileUrl, fileName: name);
    return ImageResponse(json);
  }

  /// 获取消息未读数红点
  ///
  /// http://yapi.scrm.buerkongjian.com/project/326/interface/api/24192
  Future<Map<dynamic, dynamic>> userGlobalData() async {
    var json = await HttpManager.shared.get('/user/global-data')
        as Map<dynamic, dynamic>;
    return json;
  }

  ///角色列表
  ///
  /// http://yapi.scrm.buerkongjian.com/project/326/interface/api/24114
  Future<List<RoleItemData>> roles() async {
    var json = await HttpManager.shared.get("/index/roles") as List<dynamic>;
    return json.map((e) => RoleItemData(e)).toList();
  }

  /// 获取app最新版本
  ///
  /// http://yapi.scrm.buerkongjian.com/project/326/interface/api/24966
  Future<Map<dynamic, dynamic>> appUpdate() async {
    var json = await HttpManager.shared.get("/index/last-version")
        as Map<dynamic, dynamic>;
    return json;
  }

  /// 获取二维码白名单
  ///
  /// http://yapi.scrm.buerkongjian.com/project/326/interface/api/27046
  // Future<List<String>> qrWhiteList() async {
  //   var json =
  //       await HttpManager.shared.get("/index/white-list") as List<dynamic>;
  //   return json.map((e) => "$e").toList();
  // }

  /// 获取二维码白名单
  ///
  /// http://yapi.scrm.buerkongjian.com/project/326/interface/api/27046
  Future<List<String>> qrWhiteListV2() async {
    var json =
        await HttpManager.shared.get("/index/white-list-v2") as List<dynamic>;
    return json.map((e) => "$e").toList();
  }

  /// 首页百科区
  ///
  /// http://yapi.scrm.buerkongjian.com/project/326/interface/api/27202
  Future<List<Encyclopedias>> categoryBaike() async {
    var json = await HttpManager.shared.get(
      "/index/category-baike",
    ) as List<dynamic>;
    return json.map((e) => Encyclopedias(e)).toList();
  }

  /// 获取服务器时间戳

  Future<int> getTimeStamp() async {
    // var json;
    try {
      var json = await HttpManager.shared.get(
        "/index/time-stamp",
      ) as Map;
      return json["time"] != null
          ? json["time"]
          : (DateTime.now().millisecondsSinceEpoch ~/ 1000);
    } catch (e) {
      return (DateTime.now().millisecondsSinceEpoch ~/ 1000);
    }
//
    // DLog(DateTime.now().millisecondsSinceEpoch);
  }

  /// 系统设置-一键功能开关
  ///
  /// http://yapi.scrm.buerkongjian.com/mock/326/index/setting
  Future<IndexSetting> indexSetting() async {
    var json = await HttpManager.shared.get(
      "/index/setting",
    );
    return IndexSetting.fromJson(json);
  }

  /// 权限提示
  ///

  Future getProtocolInfo() async {
    var json =
        await HttpManager.shared.get("/protocol/get", params: {'type': 6});
    return json;
  }

  /// 上传大文件
  ///
  /// http://yapi.scrm.buerkongjian.com/mock/326/index/setting
  Future<UploadDataModel> uploadData(String filename) async {
    var json = await HttpManager.shared
        .post("/upload/data", params: {"filename": filename});
    return UploadDataModel.fromJson(json);
  }

  /// 获取发送验证码次数
  ///
  /// http://yapi.scrm.buerkongjian.com/mock/326/user/send-code-count
  /// 1：手机号，2：邮箱
  Future<int> sendCodeCount(String account) async {
    var json = await HttpManager.shared.post("/user/send-code-count", params: {
      "account": account.rsa,
    });
    return json["daily_send_total"] as int? ?? 0;
  }

  /// 商品详情
  ///
// appId=dy589afc5805daa&id=36&store_id=27
// Future<GoodsInfoModel> getGoodsDetail(
//     String appId, String id, String storeid) async {
//   var json = await HttpManager.shared.get(
//     appContext.provider.userMallUrl +
//         "/api/groupBuy/v1/goods/goods/goods-detail?appId=$appId&id=$id&store_id=$storeid",
//   );
//   return GoodsInfoModel.fromJson(json);
// }

  /// 积分商品详情
  ///
// appId=dy589afc5805daa&id=36&store_id=27
// Future<GoodsInfoModel> getGoodsIntegralDetail(
//     String appId, String id, String storeid) async {
//   var json = await HttpManager.shared.get(
//     appContext.provider.userMallUrl +
//         "/api/integral/v1/goods/goods/$id?appId=$appId&id=$id&store_id=$storeid",
//   );
//   return GoodsInfoModel.fromJson(json);
// }
}

///登录授权
class APILogin {
  /// 获取授权code
  ///
  /// http://yapi.scrm.buerkongjian.com/project/326/interface/api/23095
  Future<String> authorize(String appID, String authURL) async {
    var json = await HttpManager.shared
        .get("/oauth/authorize?appid=$appID&auth_url=$authURL");
    return json["code"] as String? ?? "";
  }

  /// 获取access_token
  ///
  /// http://yapi.scrm.buerkongjian.com/project/326/interface/api/23099
  Future<AccessToken> accessToken(
      String appID, String appSecret, String authCode) async {
    var json = await HttpManager.shared.get(
        "/oauth/access-token?appid=$appID&appsecret=$appSecret&auth_code=$authCode");
    var token = json["access_token"] as String? ?? "";
    var expire = json["expire_in"] as int? ?? 0;
    var openID = json["openid"] as String? ?? "";
    return AccessToken(token, expire, openID);
  }

  /// 三方获取用户信息
  ///
  /// http://yapi.scrm.buerkongjian.com/project/326/interface/api/23103
  Future<ThirdUserInfo> userInfo(String access_token, String open_id) async {
    var json = await HttpManager.shared
        .get("/oauth/user-info?access_token=$access_token&open_id=$open_id");
    return ThirdUserInfo(json);
  }

  /// 获取验证码 未登录
  ///
  /// http://yapi.scrm.buerkongjian.com/project/326/interface/api/23151
  /// "type":"register",// 必须 destroy(注销),"reset-password",'login','register','forgot-password'
  Future<bool> getPhoneCode(String areaCode, String phone, String type) async {
    var json = await HttpManager.shared.post("/phone/code", params: {
      "phone": phone.rsa,
      "area_code": areaCode.isNotEmpty ? areaCode.rsa : '',
      "type": type.rsa,
      "crypt_type": "rsa",
    }) as bool;
    return json;
  }

  /// 获取验证码 未登录
  ///
  /// http://yapi.msvoicepower.com/project/326/interface/api/582
  /// //register_type 渠道（1=手机号，2=邮箱,3=注册号，4=护照号)
  Future<String> postRegisterType(String account) async {
    var json = await HttpManager.shared.post("/login/register-type", params: {
      "account": account.rsa,
    });
    return json['register_type'].toString();
  }

  /// 获取邮箱验证码
  ///
  /// http://yapi.scrm.buerkongjian.com/project/326/interface/api/23151
  /// "type":"register",// 必须 destroy(注销),"reset-password",'login','register','forgot-password'
  Future<bool> getEmailCode(String email, String type) async {
    var json = await HttpManager.shared.post("/email/code", params: {
      "email": email.rsa,
      "type": type.rsa,
      "crypt_type": "rsa",
    }) as bool;
    return json;
  }

  /// 获取验证码 已登录
  ///
  /// http://yapi.scrm.buerkongjian.com/project/326/interface/api/23151
  Future<bool> getPhoneCode2(String type) async {
    var json = await HttpManager.shared.post("/phone/code", params: {
      "type": type.rsa,
      "crypt_type": "rsa",
    }) as bool;
    return json;
  }

  /// 验证码登录
  ///
  /// http://yapi.scrm.buerkongjian.com/project/326/interface/api/23155
  Future<UserInfo> phoneCodeLogin(
      String areaCode, String phone, String code) async {
    var json = await HttpManager.shared.post("/phone/login-code", params: {
      "area_code": areaCode.rsa,
      "phone": phone.rsa,
      "code": code.rsa,
      "crypt_type": "rsa",
    });
    return UserInfo.update(json);
  }

  /// 邮箱验证码登录
  ///
  /// http://yapi.scrm.buerkongjian.com/project/326/interface/api/28472
  Future<UserInfo> emailCodeLogin(String email, String code) async {
    var json = await HttpManager.shared.post("/email/login-code", params: {
      "email": email.rsa,
      "code": code.rsa,
      "crypt_type": "rsa",
    });
    return UserInfo.update(json);
  }

  /// 手机号密码登录
  ///
  /// http://yapi.scrm.buerkongjian.com/project/326/interface/api/23175
  Future<UserInfo> phoneSecretLogin(
      String areaCode, String phone, String password) async {
    var json = await HttpManager.shared.post("/phone/login", params: {
      "area_code": areaCode.rsa,
      "phone": phone.rsa,
      "password": password.rsa,
      "crypt_type": "rsa",
    });
    return UserInfo.update(json);
  }

  /// 账号密码登录V2
  ///
  /// http://yapi.msvoicepower.com/project/326/interface/api/574
  ///
  Future<UserInfo> accountLogin(
      String account, String password, String device) async {
    var json = await HttpManager.shared.post("/login/login", params: {
      // "account": account.rsa,
      // "password": password.rsa,
      "account": EncryptUtils.encryptNewAES(account),
      "password": EncryptUtils.encryptNewAES(password),
      'device': device,
      'device_brand': Platform.isIOS
          ? "${appContext.iOSInfo.model}"
          : "${appContext.andriodInfo.model}",
      'device_version': Platform.isIOS
          ? "${appContext.iOSInfo.systemVersion}"
          : "${appContext.andriodInfo.version.release}",
      'device_network': appContext.connectionStatus.toString(),
    });
    return UserInfo.update(json);
  }

  /// 账号密码登录V2
  ///
  /// http://yapi.msvoicepower.com/project/326/interface/api/570
  Future<UserInfo> accountCodeLogin(
      String account, String code, String device) async {
    var json = await HttpManager.shared.post("/login/login-code", params: {
      "account": EncryptUtils.encryptNewAES(account),
      "code": EncryptUtils.encryptNewAES(code),
      'device': device,
      'device_brand': Platform.isIOS
          ? "${appContext.iOSInfo.model}"
          : "${appContext.andriodInfo.model}",
      'device_version': Platform.isIOS
          ? "${appContext.iOSInfo.systemVersion}"
          : "${appContext.andriodInfo.version.release}",
      'device_network': appContext.connectionStatus.toString(),
    });
    return UserInfo.update(json);
  }

  /// 账号登录验证码V2
  ///
  /// http://yapi.msvoicepower.com/project/326/interface/api/562
  Future<bool> accountCode(String account) async {
    var json = await HttpManager.shared.post("/login/code", params: {
      "account": account.rsa,
    }) as bool;
    return json;
  }

  /// 邮箱密码登录
  ///
  /// http://yapi.scrm.buerkongjian.com/project/326/interface/api/28264
  Future<UserInfo> emailSecretLogin(String email, String password) async {
    var json = await HttpManager.shared.post("/email/login", params: {
      "email": email.rsa,
      "password": password.rsa,
      "crypt_type": "rsa",
    });
    return UserInfo.update(json);
  }

  /// 手机号注册
  ///
  /// http://yapi.scrm.buerkongjian.com/project/326/interface/api/23179
  Future<UserInfo> phoneRegister(
      String areaCode, String phone, String password, String code,
      {required String device}) async {
    var json = await HttpManager.shared.post("/phone/register-v2", params: {
      "area_code": areaCode.rsa,
      "phone": phone.rsa,
      "password": password.rsa,
      "code": code.rsa,
      "crypt_type": "rsa",
      "device": device,
      'device_brand': Platform.isIOS
          ? "${appContext.iOSInfo.model}"
          : "${appContext.andriodInfo.model}",
      'device_version': Platform.isIOS
          ? "${appContext.iOSInfo.systemVersion}"
          : "${appContext.andriodInfo.version.release}",
      'device_network': appContext.connectionStatus.toString(),
    });
    return UserInfo.update(json);
  }

  /// 邮箱注册
  ///
  /// http://yapi.scrm.buerkongjian.com/project/326/interface/api/28256
  Future<UserInfo> emailRegister(String email, String password, String code,
      {required String device}) async {
    var json = await HttpManager.shared.post("/email/register-v2", params: {
      "email": email.rsa,
      "password": password.rsa,
      "code": code.rsa,
      "crypt_type": "rsa",
      "device": device,
      'device_brand': Platform.isIOS
          ? "${appContext.iOSInfo.model}"
          : "${appContext.andriodInfo.model}",
      'device_version': Platform.isIOS
          ? "${appContext.iOSInfo.systemVersion}"
          : "${appContext.andriodInfo.version.release}",
      'device_network': appContext.connectionStatus.toString(),
    });
    return UserInfo.update(json);
  }

  /// 忘记密码重置密码
  ///
  /// http://yapi.scrm.buerkongjian.com/project/326/interface/api/23394
  Future<bool> phonePassword(String phone, String password, String code) async {
    var json = await HttpManager.shared.put("/phone/password-v2", params: {
      // "area_code": areaCode.rsa,
      "phone": phone.rsa,
      "password": password.rsa,
      "code": code.rsa,
      "type": "forgot-password".rsa,
      "crypt_type": "rsa",
    });
    return json as bool;
  }

  ///邮箱 忘记密码重置密码
  ///
  /// http://yapi.scrm.buerkongjian.com/project/326/interface/api/28280
  Future<bool> emailPassword(String email, String password, String code) async {
    var json = await HttpManager.shared.put("/email/password", params: {
      "email": email.rsa,
      "password": password.rsa,
      "code": code.rsa,
      "type": "forgot-password".rsa,
      "crypt_type": "rsa",
    });
    return json as bool;
  }

  /// 获取区号列表
  ///
  /// http://yapi.scrm.buerkongjian.com/project/326/interface/api/23400
  Future<List<AreaCodeData>> areaList() async {
    var json = await HttpManager.shared.get(
      "/phone/area-code",
    ) as List<dynamic>;
    return json.map((e) => AreaCodeData(e)).toList();
  }

  /// 手机验证验证码
  ///忘记密码forgot-password，重置密码reset-password，注销destroy
  /// http://yapi.scrm.buerkongjian.com/project/326/interface/api/28296
  Future<bool> phoneVerifyCode(String type, String phone, String code) async {
    var json = await HttpManager.shared.post("/phone/verify-code", params: {
      "type": type.rsa,
      "phone": phone.rsa,
      "code": code.rsa,
      "crypt_type": "rsa",
    });
    return json as bool;
  }

  /// 邮箱验证验证码
  ///忘记密码forgot-password，重置密码reset-password，注销destroy
  /// http://yapi.scrm.buerkongjian.com/project/326/interface/api/28288
  Future<bool> emailVerifyCode(String type, String email, String code) async {
    var json = await HttpManager.shared.post("/email/verify-code", params: {
      "type": type.rsa,
      "email": email.rsa,
      "code": code.rsa,
      "crypt_type": "rsa",
    });
    return json as bool;
  }
}

/// 用户
class APIUser {
  /// 获取用户信息
  ///
  /// http://yapi.scrm.buerkongjian.com/project/326/interface/api/23364
  Future<UserInfo> getUserInfo() async {
    var json = await HttpManager.shared.get("/user/get", params: {});
    return UserInfo.update(json);
  }

  /// 编辑用户信息
  ///
  /// http://yapi.scrm.buerkongjian.com/project/326/interface/api/23370
  ///
  /// type  昵称:nickname,  头像：avatar， 性别：sex,  birthday:生日
  Future<UserInfo> updateUserInfo(String type, dynamic value) async {
    var json = await HttpManager.shared.put("/user/update", params: {
      "type": type,
      "value": value,
    });
    var ctx = navigatorKey.currentContext;
    if (ctx != null && type != 'lang') {
      // if (isShowToast) {
      customShowSuccess(S.of(ctx).changed_successfully);
      // }
    }
    return getUserInfo();
  }

  Future<MessageListModel> getServiceMsg(int lastid,
      {String source = 'self', int pagesize = 20}) async {
    var json = await HttpManager.shared.get(
        "/chat/history?last_id=$lastid&page_size=$pagesize&source=$source");
    return MessageListModel.fromJson(json);
  }

  ///获取Websocket连接的url
  ///http://yapi.scrm.buerkongjian.com/project/326/interface/api/28512
  Future<dynamic> getServiceUrl(String source) async {
    var json = await HttpManager.shared.get("/chat/url?source=$source");
    return json;
  }

  ///修改密码
  ///
  /// http://yapi.scrm.buerkongjian.com/project/326/interface/api/23376
  Future<bool> password(String code, String password) async {
    bool json = await HttpManager.shared.put("/user/password", params: {
      "code": code.rsa,
      "password": password.rsa,
      "crypt_type": "rsa",
    });
    return json;
  }

  ///登出
  ///
  /// http://yapi.scrm.buerkongjian.com/project/326/interface/api/24030
  Future<bool> logout() async {
    var json = await HttpManager.shared.get("/user/logout") as bool;
    return json;
  }

  ///认证角色
  ///
  ///[params]
  ///
  /// {
  //     "role":1,// 角色id // 通过角色接口获取
  //     "country":"中国",// 国籍名
  //     "country_code":"CHN",// 国家编码,通过参数国家接口过去
  //     "family_name":"唐", // 姓
  //     "given_name":"超", // 名
  //     "certificate_type":1, // 证件类型 I0001:护照 I0002:身份证，I0003:台湾居民来往大陆通行证 I0004:港澳居民来往内地同行证
  //     "license_number":"430821199209277016", // 证件号
  //     "registration_number":""// 注册码。可为空，由用户手动填写
  // }
  ///
  /// http://yapi.scrm.buerkongjian.com/project/326/interface/api/24120
  Future<AuthTypeItemData> authentication(Map<String, dynamic> params) async {
    var json =
        await HttpManager.shared.post("/user/authentication", params: params);
    return AuthTypeItemData(json);
  }

  ///修改用户角色
  ///
  ///http://yapi.scrm.buerkongjian.com/project/326/interface/api/24186
  Future<bool> changeRole(String role) async {
    var json = await HttpManager.shared
        .put("/user/change-role", params: {"role": role}) as bool;
    return json;
  }

  ///角色列表
  ///
  /// http://yapi.scrm.buerkongjian.com/project/326/interface/api/24180
  Future<List<RoleItemData>> roles() async {
    var json = await HttpManager.shared.get("/user/roles") as List<dynamic>;
    return json.map((e) => RoleItemData(e)).toList();
  }

  // 证件类型
  Future<List<CardsItemData>> cards() async {
    var json =
        await HttpManager.shared.get("/user/credentials-type") as List<dynamic>;
    return json.map((e) => CardsItemData(e)).toList();
  }

  // 问题选项
  Future quetionOptions() async {
    var json = await HttpManager.shared.get("/user/question-options");
    return json;
  }

  // 二次验证
  Future<bool> authenticationConfirm(Map<String, dynamic> params) async {
    var json = await HttpManager.shared
        .post("/user/authentication-confirm", params: params) as bool;
    return json;
  }

  ///注销账户
  ///
  /// http://yapi.scrm.buerkongjian.com/project/326/interface/api/24210
  Future<bool> destroy(String code) async {
    var json = await HttpManager.shared
        .post("/user/destroy", params: {"code": code}) as bool;
    return json;
  }

  /// 是否显示投稿按钮
  ///
  /// http://yapi.scrm.buerkongjian.com/project/326/interface/api/25210
  Future<bool> volunteerShow() async {
    var json =
        await HttpManager.shared.get('/volunteer/show-manuscript-btn') as bool;
    return json;
  }

  /// 签到详情
  ///
  /// http://yapi.scrm.buerkongjian.com/project/326/interface/api/27632
  Future<SignInData> signDetail(String month) async {
    // var date = DateTime.now();
    // var month = "${date.year}-${date.month}";
    var url =
        "${appContext.provider.userMallUrl}/api/sign/sign-detail?moth=$month";
    var json = await HttpManager.shared.request('GET', url) as dynamic;
    var result = SignInData(json);
    return result;
  }

  /// 签到
  ///
  /// http://yapi.scrm.buerkongjian.com/project/326/interface/api/27640
  Future<void> sign() async {
    var url = "${appContext.provider.userMallUrl}/api/sign/sign";
    var json = await HttpManager.shared.request('GET', url) as dynamic;
    DLog(json);
  }

  /// 关于我们
  ///
  Future<dynamic> agreements(int type) async {
    var url = "/index/agreements?type=$type";
    var json = await HttpManager.shared.get(url) as dynamic;
    return json;
  }

  /// 安卓权限提示
  Future<dynamic> agreementsV2(int type) async {
    var url = "/index/agreements-v2?type=$type";
    var json = await HttpManager.shared.get(url) as dynamic;
    return json;
  }
}

///文章
class APIArticle {
  /// 文章列表
  ///
  /// http://yapi.scrm.buerkongjian.com/project/326/interface/api/23231
  /// 首页type为：focus
  Future<List<ArticleListItem>> articleList(int page,
      {String? alias, int limit = 15, String? search}) async {
    if (search != null) {
      search = Uri.encodeFull(search);
    }
    // var json = await HttpManager.shared.get(
    //     "/article/list?page=1&limit=1000&alias=column_173951652274570&lang=zh")
    var json = await HttpManager.shared.get(
            "/article/list?page=$page&limit=$limit${search != null ? "&search=$search" : ""}${alias != null ? "&alias=$alias" : ""}")
        as List<dynamic>;
    return json.map((e) => ArticleListItem(e)).toList();
  }

  ///获取文章详情
  ///
  ///http://yapi.scrm.buerkongjian.com/project/326/interface/api/23235
  Future<ArticleListItem> detail(String id) async {
    var json = await HttpManager.shared.get("/article/get?id=$id");
    return ArticleListItem(json);
  }

  ///获取文章tab
  ///
  ///http://yapi.scrm.buerkongjian.com/project/326/interface/api/23508
  Future<List<ArticleTypes>> articleTypes() async {
    var json = await HttpManager.shared.get("/article/tabs") as List<dynamic>;
    return json.map((e) => ArticleTypes(e)).toList();
  }

  ///获取资讯tab
  ///
  ///http://yapi.msvoicepower.com/project/326/interface/api/550
  Future<List<ArticleTypes>> articleIndexTypes() async {
    var json = await HttpManager.shared.get("/index/info-cms") as List<dynamic>;
    return json.map((e) => ArticleTypes(e)).toList();
  }

  ///获取资讯列表
  ///
  ///http://yapi.msvoicepower.com/project/326/interface/api/558
  Future<List<ArticleListItem>> articleInformationList(
    int page, {
    String? id,
    int limit = 15,
  }) async {
    // if (search != null) {
    //   search = Uri.encodeFull(search);
    // }
    var json = await HttpManager.shared.get(
        "/article/information?page=$page&limit=$limit${id != null ? "&id=$id" : ""}");
    // DLog(json);
    List<dynamic> rows;
    if (json is List) {
      rows = json;
    } else {
      rows = json['data'];
    }

    return rows.map((e) => ArticleListItem(e)).toList();
  }

  /// 文章相关推荐
  ///
  /// http://yapi.scrm.buerkongjian.com/project/326/interface/api/23760
  Future<List<ArticleListItem>> articleRecommend(String id) async {
    var json = await HttpManager.shared.get("/article/recommend?id=$id")
        as List<dynamic>;
    return json.map((e) => ArticleListItem(e)).toList();
  }
}

///推送绑定
class APINotificationBind {
  /// 绑定推送
  ///
  /// http://yapi.scrm.buerkongjian.com/project/326/interface/api/23352
  Future<bool> bind(String registration_id, int platform) async {
    await HttpManager.shared.put("/user/set-alias",
        params: {"registration_id": registration_id, "platform_id": platform});
    return true;
  }

  /// 解除绑定
  ///
  /// http://yapi.scrm.buerkongjian.com/project/326/interface/api/23358
  Future<bool> del(String registration_id) async {
    await HttpManager.shared
        .del("/user/del-alias", params: {"registration_id": registration_id});
    return true;
  }
}

/// 防疫
class Epidemic {
  ///获取健康申报表单
  ///
  /// http://yapi.scrm.buerkongjian.com/project/326/interface/api/23730
  Future<EpdemciForm> form() async {
    var json = await HttpManager.shared.get("/epidemic/form");
    return EpdemciForm(json);
  }

  ///提交防疫表单
  ///
  /// http://yapi.scrm.buerkongjian.com/project/326/interface/api/23736
  Future<bool> report(String formId, String? date, List data) async {
    var result = await HttpManager.shared.post("/epidemic/report", params: {
      'form_id': formId,
      'date': date,
      'report': data.map((e) => e.json).toList()
    });
    return result;
  }

  ///获取填报详情
  ///
  /// http://yapi.scrm.buerkongjian.com/project/326/interface/api/23742
  Future<List<EpidemicItem>> reportDetail(String id) async {
    var json = await HttpManager.shared.get("/epidemic/report-detail?id=$id")
        as List<dynamic>;
    return json.map((e) => EpidemicItem(e)).toList();
  }

  ///获取用户是否已经健康打卡
  ///
  /// http://yapi.scrm.buerkongjian.com/project/326/interface/api/23748
  Future<bool> isReport() async {
    var result = await HttpManager.shared.get("/epidemic/is-reported");
    return result;
  }

  ///获取是否有新的填报需求
  ///
  ///http://yapi.scrm.buerkongjian.com/project/326/interface/api/23808
  Future<bool> isNewReport() async {
    var result = await HttpManager.shared.get("/epidemic/has-new-report");
    return result;
  }

  ///近14天填报记录
  ///
  /// http://yapi.scrm.buerkongjian.com/project/326/interface/api/23754
  Future<List<EpidemicRecordItem>> reportRecord() async {
    var json = await HttpManager.shared.get("/epidemic/report-record")
        as List<dynamic>;
    return json.map((e) => EpidemicRecordItem(e)).toList();
  }

  ///健康二维码
  ///
  /// http://yapi.scrm.buerkongjian.com/project/326/interface/api/24126
  Future<EpidemicQRCode> qrCode() async {
    var json = await HttpManager.shared.get("/epidemic/qrcode")
        as Map<String, dynamic>;
    return EpidemicQRCode(json);
  }

  ///
  ///防疫数据
  ///
  /// http://yapi.scrm.buerkongjian.com/project/326/interface/api/24174
  Future<EpidemicData> data() async {
    var json =
        await HttpManager.shared.get("/epidemic/data") as Map<String, dynamic>;
    return EpidemicData(json);
  }

  //核酸数据
  Future<EpidemicHSData> hssjData() async {
    var json = await HttpManager.shared.get("/epidemic/hsjccx")
        as Map<String, dynamic>;
    return EpidemicHSData(json);
  }

  Future<EpidemicYMData> ymjkData() async {
    var json = await HttpManager.shared.get("/epidemic/ymjzjl")
        as Map<String, dynamic>;
    return EpidemicYMData(json);
  }

  ///获取用户防疫打卡状态
  ///
  /// [return]：reported ， hasNew
  ///
  /// http://yapi.scrm.buerkongjian.com/project/326/interface/api/24540
  Future<Map<String, dynamic>> reportStatus() async {
    var json = await HttpManager.shared.get("/epidemic/report-status")
        as Map<String, dynamic>;
    return json;
  }

  ///用户提交疫苗或核酸检测报告 "type":1, // 1：核酸检测，2：疫苗接种报告
  ///
  /// http://yapi.scrm.buerkongjian.com/mock/326/epidemic/user-report-submit
  Future<bool> reportSubmit(int type, String url, String filename) async {
    var json = await HttpManager.shared.post("/epidemic/user-report-submit",
        params: {"type": type, "url": url, "filename": filename});
    return true;
  }

  ///获取用户疫苗或者核酸检测报告提交列表 "type":1, // 1：核酸检测，2：疫苗接种报告
  ///
  /// http://yapi.scrm.buerkongjian.com/mock/326/epidemic/user-report-list
  Future<List<dynamic>> reportList(int type) async {
    var json = await HttpManager.shared
        .get("/epidemic/user-report-list?type=$type") as List<dynamic>;
    return json;
  }

  ///健康知识库
  ///
  /// http://yapi.scrm.buerkongjian.com/mock/326/health/knowledge-list
  Future<List<HealthAboutInfo>> healthKnowledgeList(
      {required int page, int limit = 15}) async {
    var json = await HttpManager.shared
        .get("/health/knowledge-list?page=$page&limit=$limit");
    List<HealthAboutInfo> list = [];
    if (json is List) {
      json.forEach((element) {
        list.add(HealthAboutInfo.fromJson(element));
      });
    }
    return list;
  }

  ///健康宣传
  ///
  /// http://yapi.scrm.buerkongjian.com/mock/326/health/propaganda-list
  Future<List<HealthAboutInfo>> healthPropagandaList(
      {required int page, int limit = 15}) async {
    var json = await HttpManager.shared
        .get("/health/propaganda-list?page=$page&limit=$limit");
    List<HealthAboutInfo> list = [];
    if (json is List) {
      json.forEach((element) {
        list.add(HealthAboutInfo.fromJson(element));
      });
    }
    return list;
  }

  ///健康信息发布
  ///
  /// http://yapi.scrm.buerkongjian.com/mock/326/health/message-list
  Future<List<HealthAboutInfo>> healthMessageList(
      {required int page, int limit = 15}) async {
    var json = await HttpManager.shared
        .get("/health/message-list?page=$page&limit=$limit");
    List<HealthAboutInfo> list = [];
    if (json is List) {
      json.forEach((element) {
        list.add(HealthAboutInfo.fromJson(element));
      });
    }
    return list;
  }
}

///志愿者小站
class APIVolunteer {
  ///志愿者小站列表
  ///
  /// http://yapi.scrm.buerkongjian.com/project/326/interface/api/23712
  Future<List<VolunteerHouseItem>> houseList({String? search}) async {
    var path = "/volunteer/house-list";
    if (search != null) {
      path = "/volunteer/house-list?search=$search";
    }
    var json = await HttpManager.shared.get(path) as List<dynamic>;
    return json.map((e) => VolunteerHouseItem(e)).toList();
  }

  ///志愿者新闻列表
  ///
  /// http://yapi.scrm.buerkongjian.com/project/326/interface/api/23718
  Future<List<ArticleListItem>> newsList(int page, {int limit = 15}) async {
    var json = await HttpManager.shared
        .get("/volunteer/news-list?page=$page&limit=$limit") as List<dynamic>;
    return json.map((e) => ArticleListItem(e)).toList();
  }
}

///场馆
class APIVenue {
  ///场馆列表
  ///
  /// http://yapi.scrm.buerkongjian.com/project/326/interface/api/24036
  Future<List<VenueItem>> list({String? search}) async {
    var json = await HttpManager.shared
            .get("/venue/list${search != null ? "?search=$search" : ""}")
        as List<dynamic>;
    return json.map((e) => VenueItem(e)).toList();
  }

  ///场馆详情
  ///
  /// http://yapi.scrm.buerkongjian.com/project/326/interface/api/24042
  Future<VenueItem> detail(String id) async {
    var json = await HttpManager.shared.get("/venue/get?id=$id");
    return VenueItem(json);
  }

  ///场馆新闻列表
  ///
  /// http://yapi.scrm.buerkongjian.com/project/326/interface/api/24048
  Future<List<ArticleListItem>> newsList(String id) async {
    var json = await HttpManager.shared
        .get("/venue/news-list?id=$id&page=1&limit=1000") as List<dynamic>;
    return json.map((e) => ArticleListItem(e)).toList();
  }

  ///场馆比赛列表
  ///
  /// http://yapi.scrm.buerkongjian.com/project/326/interface/api/25050
  Future<List<VenueSubscriptionEntity>> gameList(String id) async {
    var json = await HttpManager.shared
        .get("/venue/game-schedule?id=$id&page=1&limit=1000") as List<dynamic>;
    return json.map((e) => VenueSubscriptionEntity(e)).toList();
  }
}

///赛事
class APIGame {
  ///赛事参赛国家列表
  ///
  /// http://yapi.scrm.buerkongjian.com/project/326/interface/api/24060
  Future<List<GameDataItem>> country() async {
    var json = await HttpManager.shared.get("/game/country") as List<dynamic>;
    return json.map((e) => GameDataItem(e)).toList();
  }

  ///赛事比赛项目列表
  ///
  /// http://yapi.scrm.buerkongjian.com/project/326/interface/api/24066
  Future<List<GameDetail>> items({String? search}) async {
    var json = await HttpManager.shared
            .get("/game/items${search != null ? "?search=$search" : ""}")
        as List<dynamic>;
    return json.map((e) => GameDetail(e)).toList();
  }

  ///赛事详情
  Future<GameDetail> itemDetail(String id) async {
    var json = await HttpManager.shared.get("/game/item-detail?id=$id")
        as Map<String, dynamic>;
    return GameDetail(json);
  }

  ///赛事订阅
  Future<bool> subscribe(GameSubcriptionManageData data) async {
    List<Map<String, dynamic>> list = [];
    list.addAll(
      data.discipline.map((e) => {"discipline": e.discipline}).toList(),
    );
    list.addAll(
      data.venue.map((e) => {"venue_code": e.code}).toList(),
    );
    var json = await HttpManager.shared
        .post("/game/subscribe", params: {"data": list}) as bool;
    return json;
  }

  ///赛事取消订阅
  Future<bool> cancelSubscribe(String type, String code) async {
    var json = await HttpManager.shared
        .del("/game/cancel-subscribe", params: {"type": type, "code": code});
    return true;
  }

  ///我的订阅列表
  Future<GameSubcriptionManageData> mySubscribe() async {
    var json = await HttpManager.shared.get("/game/subscribe-list")
        as Map<String, dynamic>;
    return GameSubcriptionManageData.load(json);
  }

  ///订阅列表
  Future<List<GameSubscriptionDataItem>> subscribeList(int page,
      {int pageSize = 15}) async {
    var json = await HttpManager.shared
        .get("/game/game-subscribe-list?page=$page&limit=$pageSize");
    if (json is Map<String, dynamic>) {
      var value = json as Map<String, dynamic>;
      return GameSubscriptionData(value).list;
    }
    return [];
  }

  Future<List<GameTabData>> tabs() async {
    var json = await HttpManager.shared.get("/game/tabs") as List<dynamic>;
    return json.map((e) => GameTabData(e)).toList();
  }

  Future<List<WardData>> wards() async {
    var json =
        await HttpManager.shared.get("/game/medal-rank") as List<dynamic>;
    return json.map((e) => WardData(e)).toList();
  }

  ///赛程列表
  /// date 2021-08-23 status 0全部 1未开始 2已结束 3进行中 4未安排
  /// http://yapi.scrm.buerkongjian.com/mock/326/game-schedule/list
  Future<List<dynamic>> scheduleList(bool forward, int page, int limit,
      String type, String venue, String status, String date,
      {String? search}) async {
    var direction = 'forward';
    direction = forward ? 'forward' : 'backward';
    var json = await HttpManager.shared.get(
            "/game-schedule/list?direction=$direction"
            "&page=$page&limit=$limit&discipline=$type&venue=$venue&status=$status&date=$date${search != null ? "&search=$search" : ""}")
        as Map<String, dynamic>;
    var list = json["list"] as List<dynamic>;
    return list;
  }

  ///订阅单个比赛
  Future<bool> subscribeMatch(String id) async {
    var json = await HttpManager.shared
        .post("/game/game-subscribe", params: {"id": id});
    return true;
  }

  ///赛程取消订阅
  Future<bool> cancelMatchSubscribe(String id) async {
    var json = await HttpManager.shared
        .post("/game/cancel-game-subscribe", params: {"schedule_id": id});
    return true;
  }

  ///game-schedule/detail
  Future<GameDetailData> scheduleDetail(String id) async {
    var json = await HttpManager.shared.get("/game-schedule/detail?id=$id")
        as Map<String, dynamic>;
    return GameDetailData(json);
  }

  /// 奖牌榜
  ///
  /// http://yapi.scrm.buerkongjian.com/project/326/interface/api/25092
  Future<List<GameMedalRankModel>> gameMedalRankList(int page,
      {int size = 15}) async {
    var json = await HttpManager.shared
        .get("/game/medal-rank?page=$page&limit=$size") as List<dynamic>;
    var res = json.map((e) {
      var tmp = GameMedalRankModel.fromJson(e);
      return tmp;
    }).toList();
    return res;
  }

  ///game-schedule/detail
  Future<GameDetailData> videoDetail(String id) async {
    var json = await HttpManager.shared.get("/game-video/detail?id=$id")
        as Map<String, dynamic>;
    return GameDetailData(json);
  }

  Future<dynamic> gameInfoList(String rsc) async {
    var json = await HttpManager.shared.get(
            "https://results.2021chengdu.com/api/tp/result/info_list?key=9227a3c37dca4d8cab34cbed72f4c748&rsc=$rsc")
        as Map<String, dynamic>;
    return json;
  }

// https://results.2021chengdu.com/api/tp/result/info_list?key=9227a3c37dca4d8cab34cbed72f4c748&rsc=FENMSABRE-------------P1----------
  /// 获取赛事的日期列表
  ///
  /// http://yapi.scrm.buerkongjian.com/project/326/interface/api/25212
  Future<List<DateTime>> gameDateList() async {
    var json = await HttpManager.shared.get("/game-schedule/game-date-list")
        as List<dynamic>;
    var res = json.map((e) {
      var tmp = DateTime.parse(e);
      return tmp;
    }).toList();
    return res;
  }

  /// 获取视频列表
  ///
  /// http://yapi.scrm.buerkongjian.com/project/326/interface/api/26892
  ///
  /// [type] 1:直播，2:点播
  Future<List<GameVideoListItem>> gameVideoList(int type,
      {String? venue, String? discipline}) async {
    var path = "/game-video/get-list?video_type=$type";
    if (venue != null) {
      path += "&venue=$venue";
    }
    if (discipline != null) {
      path += "&discipline=$discipline";
    }
    var json = await HttpManager.shared.get(path) as List<dynamic>;
    var res = json.map((e) {
      return GameVideoListItem(e);
    }).toList();
    return res;
  }

  /// 获取赛事订阅的推荐
  ///
  /// http://yapi.scrm.buerkongjian.com/project/326/interface/api/25212
  Future<List<GameSubscriptionDataItem>> recommendSchedule() async {
    var json = await HttpManager.shared.get("/game/recommend-schedule")
        as List<dynamic>;
    var res = json.map((e) => GameSubscriptionDataItem(e)).toList();
    return res;
  }

  /// 获取世运之眼的列表
  ///
  /// http://yapi.scrm.buerkongjian.com/project/326/interface/api/25212
  Future<List<VenueItem>> eyeList(int page, {int size = 15}) async {
    // try {
    var json = await HttpManager.shared
        .get("/eye/get-list?page=${page}&limit=${size}") as List<dynamic>;
    var res = json.map((e) => VenueItem(e)).toList();
    return res;
    // } catch (e) {
    //   return [];
    // }
  }

  /// 获取世运之眼详情
  ///
  /// http://yapi.scrm.buerkongjian.com/project/326/interface/api/27230
  Future<GameDetailSingleData> eyeDetail(String id) async {
    var json =
        await HttpManager.shared.get("/eye/get?id=$id") as Map<String, dynamic>;
    return GameDetailSingleData(json);
  }

  ///用户评论列表
  ///
  /// http://yapi.scrm.buerkongjian.com/project/326/interface/api/28544
  Future<UserCommentModel> getUserComments(String id) async {
    var json =
        await HttpManager.shared.get("/game-comment/user-comment?id=$id");
    return UserCommentModel.fromJson(json);
  }

  ///用户可评论列表
  ///
  /// http://yapi.scrm.buerkongjian.com/project/326/interface/api/28552
  Future<List<CanCommentModel>> canUserComments(String id) async {
    var json =
        await HttpManager.shared.get("/game-comment/can-use-comment?id=$id");
    List<CanCommentModel> list = [];
    if (json is List) {
      json.forEach((element) {
        list.add(CanCommentModel.fromJson(element));
      });
    }
    return list;
  }

  ///用户可评论列表
  ///
  /// http://yapi.scrm.buerkongjian.com/project/326/interface/api/28560
  Future<bool> addUserComments(String id, List<CanCommentModel> lists) async {
    List comments = [];
    lists.forEach((element) {
      comments
          .add({"comment_id": element.id, "template_id": element.templateId});
    });
    var json = await HttpManager.shared.post("/game-comment/add-comment",
        params: {"id": id, "comment_data": comments}) as bool;
    return json;
  }
}

//消息
class Station {
  ///消息主列表
  ///
  /// http://yapi.scrm.buerkongjian.com/project/326/interface/api/24096
  Future<List<StationItem>> list(int page, {int size = 15}) async {
    var json = await HttpManager.shared
        .get("/station?page_index=$page&page_size=$size") as Map; //
    var list = json["result"] as List<dynamic>;
    return list.map((e) => StationItem(e)).toList();
  }

  ///消息子列表
  ///
  /// http://yapi.scrm.buerkongjian.com/project/326/interface/api/24102
  Future<List<StationSubItem>> subList(String publishUserId, int page,
      {int size = 15}) async {
    var json = await HttpManager.shared.get(
            "/station/sub-list?publish_user_id=$publishUserId&page_index=$page&page_size=$size")
        as Map;
    var list = json["result"] as List<dynamic>;
    return list.map((e) => StationSubItem(e)).toList();
  }

  ///删除消息
  ///
  /// http://yapi.scrm.buerkongjian.com/mock/326/station/delete
  Future<bool> postDeleteMsg(String id) async {
    var json = await HttpManager.shared
        .delete("/station/delete", params: {'publish_user_id': id}) as bool;
    return json;
  }

  ///消息清理
  ///
  /// http://yapi.scrm.buerkongjian.com/mock/326/station/clear-unread
  Future<bool> putCleanUnread() async {
    var json = await HttpManager.shared.put("/station/clear-unread") as bool;
    return json;
  }
}

class JSBridge {
  /// 获取H5授权
  /// http://yapi.scrm.buerkongjian.com/project/326/interface/api/23095
  Future<Map> authorize(String appId, String authUrl) async {
    var json = await HttpManager.shared
        .get("/authorize/code?appid=$appId&auth_url=$authUrl") as Map;
    return json;
  }

  /// 查询预支付订单
  /// http://yapi.scrm.buerkongjian.com/project/326/interface/api/24462
  Future<Map> prePayOrderInfo(String order) async {
    var json =
        await HttpManager.shared.get('/app/pay/order?pre_order=$order') as Map;
    return json;
  }

  /// 执行支付
  /// http://yapi.scrm.buerkongjian.com/project/326/interface/api/24468
  Future<Map> appPay(String pre_order, String pay_mode) async {
    var json = await HttpManager.shared.post("/app/pay/pay",
        params: {"pre_order": pre_order, "pay_mode": pay_mode}) as Map;
    return json;
  }
}

/// 意见反馈
class FeedBack {
  /// 添加反馈
  ///
  /// http://yapi.scrm.buerkongjian.com/project/326/interface/api/24282
  Future<bool> add({
    int? pid,
    int? module,
    String? subModule,
    int? type,
    required String text,
    int? moduleId,
    List<String>? images,
  }) async {
    var json = await HttpManager.shared.post("/feedback/add", params: {
      "pid": pid,
      "module": module,
      "sub_module": subModule,
      "type": type,
      "text": text,
      "images": images,
      "module_id": moduleId
    }) as bool;
    return json;
  }

  ///意见反馈列表
  ///
  /// http://yapi.scrm.buerkongjian.com/project/326/interface/api/24294
  Future<List<FeedbackItem>> list(int page, {int size = 15}) async {
    var list = await HttpManager.shared
        .get("/feedback/get-list?page=$page&limit=$size") as List<dynamic>;
    return list.isEmpty ? [] : list.map((e) => FeedbackItem(e)).toList();
  }

  ///意见反馈详情
  ///
  /// http://yapi.scrm.buerkongjian.com/project/326/interface/api/24288
  Future<FeedbackDetailData> detail(int id) async {
    var json = await HttpManager.shared.get("/feedback/detail?id=$id")
        as Map<String, dynamic>;
    return FeedbackDetailData(json);
  }

  /// 志愿者投稿
  ///
  /// http://yapi.scrm.buerkongjian.com/project/326/interface/api/24642
  Future<bool> volunteerManuscript(
      String title, String desc, String fileUrls) async {
    var json = await HttpManager.shared.post('/volunteer/manuscript', params: {
      "title": title,
      "desc": desc,
      "file_urls": fileUrls,
    }) as bool;
    return json;
  }

  /// 意见反馈场景

  Future<List> feedbackModule() async {
    var json = await HttpManager.shared.get('/feedback/module');
    return (json is List) ? json : [];
  }
// /feedback/module
}
